﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using EnvDTE;

namespace TorstenMandelkow.SharePointSoftwareFactory_HiveViewer
{
    /// <summary>
    /// Interaction logic for MyControl.xaml
    /// </summary>
    public partial class MyControl : UserControl
    {
        EnvDTE80.DTE2 dte2;

        public MyControl()
        {
            InitializeComponent();
        }

        public void Update(string content)
        {
            if (dte2 != null)
            {
                this.treeView1.Items.Clear();
                foreach (Project p in dte2.Solution.Projects)
                {
                    //TreeViewItem item = new TreeViewItem();
                    //item.Tag = "Folder";
                    //item.
                    this.treeView1.Items.Add(p.Name);
                }
            }
        }

        private void MyToolWindow_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            this.treeView1.Width = this.Width;
            this.treeView1.Height = this.Height;
        }

        private void treeView1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            TreeViewItem selectedItem = treeView1.SelectedItem as TreeViewItem;
            switch (selectedItem.Tag.ToString())
            {
                case "Folder":
                    treeView1.ContextMenu = treeView1.Resources["FolderContext"] as ContextMenu;
                    break;
                case "File":
                    treeView1.ContextMenu = treeView1.Resources["FileContext"] as ContextMenu;
                    break;
            }
        }

        internal void SetDTE(EnvDTE80.DTE2 dte2)
        {
            this.dte2 = dte2;
        }
    }
}